package com.miaostars.apakey.events;

import com.miaostars.apakey.Apakey;
import com.miaostars.apakey.checks.XRayChecks;
import com.miaostars.apakey.utils.AlertManager;
import com.miaostars.apakey.utils.PlayerData;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.BlockBreakEvent;

public class BlockListener implements Listener {
    
    private final Apakey plugin;
    private final XRayChecks xRayChecks;
    private final AlertManager alertManager;
    
    public BlockListener(Apakey plugin) {
        this.plugin = plugin;
        this.xRayChecks = new XRayChecks(plugin);
        this.alertManager = plugin.getAlertManager();
    }
    
    @EventHandler
    public void onBlockBreak(BlockBreakEvent event) {
        Player player = event.getPlayer();
        PlayerData data = PlayerData.get(player);
        Block block = event.getBlock();
        
        if (xRayChecks.checkXRay(player, data, block)) {
            alertManager.alert(player, "XRay", "A");
            event.setCancelled(true);
        }
    }
}
